<%-- 
    Document   : lock
    Created on : Oct 14, 2014, 2:37:22 PM
    Author     : Admin
--%>

<%@ include file="/WEB-INF/jsp/include/page_header.jspf" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Lock Session</title>
        <script type="text/javascript">
            var isCookie = true;
            var timeoutHandle = null;
            
            $(document).ready(function(){
                $('#unlock').hide();
                getCookie();
//                justMsg();
            });
            
            function getCookie(){
//                var exp = '<%= session.getAttribute("sesExpired") %>';
                var exp = getCookieValue("expSession");
                if(document.cookie && document.cookie.indexOf("lockSession=alreadyLock") !== -1){
                    isCookie = true;
                    document.getElementById('sessionExp').innerHTML = 'This session will expired on ' + exp +'.';
                    document.getElementById('sessionMsg').innerHTML = 'You will be redirect to login page automatically after that. ';
                }else{
                    isCookie = false;
                    window.location.href = '${pageContext.request.contextPath}/logout';
//                    $('#unlock').show();
                }
                timeoutHandle = setTimeout(function () { getCookie();}, '1000');
            }
            
            function getCookieValue(cname) {
                var name = cname + "=";
                var ca = document.cookie.split(';');
                for(var i=0; i<ca.length; i++) {
                    var c = ca[i];
                    while (c.charAt(0)=== ' ') c = c.substring(1);
                    if (c.indexOf(name) !== -1) return c.substring(name.length,c.length);
                }
                return "";
            }
            
            function justMsg(){
                document.getElementById('sessionExp').innerHTML = 'Cookie contains lockSession :'+document.cookie.contains("lockSession");
                document.getElementById('sessionMsg').innerHTML = 'Cookie indexof lockSession :'+document.cookie.indexOf("lockSession");
                timeoutHandle = setTimeout(function () { justMsg();}, '1000');
            }
          </script>
    </head>
    <body>
        <s:messages/>
        <s:errors/>
        <div id="page-title">
            <span class="title">MATS : Session Lock</span>
        </div>
        <br>

        <div id="page-content">                 
            <section class="container">           
                <center>
                    Session Lock after login attempt in ${actionBean.sesMaxAttempt} times<br />
                    <div id="sessionExp"></div>
                    <div id="sessionMsg"></div>
                    <div id="unlock">                        
                        <a href="${pageContext.request.contextPath}/logout">clear session</a>
                    </div>
                </center>
            </section>
        </div>
    </body>
</html>